package archimede;

import it.sauronsoftware.ftp4j.FTPClient;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Dictionary;
import java.util.HashMap;
import java.util.Properties;
import java.util.Scanner;

public class TagPuntiCritici {

  private HashMap<String, String> tag = new HashMap<String, String>();

  public TagPuntiCritici() {
    Properties pc = System.getProperties();
    String homePath = pc.getProperty("user.home");
    String tagProject = homePath + pc.getProperty("file.separator")
        + "ArchimedeSuper" + pc.getProperty("file.separator") + "tag.txt";
    try {
      FTPClient client = new FTPClient();
      // connessione
      client.setPassive(true);
      client.connect("eureka.archimedegroup.eu");
      // login
      client.login("stefano", "0901");
      //
      client.changeDirectory("ProgettoArchimede");

      try {
        client.download("tag.txt", new File(tagProject));
      } catch (Throwable e2) {
        e2.printStackTrace();
      }
      // client.logout();
      client.disconnect(true);
    } catch (Exception e) {
    }
    try {
      File toScan = new File(tagProject);
      Scanner c = new Scanner(toScan);
      String attribute = "";
      String value = "";
      while (c.hasNextLine()) {
        String line = c.nextLine();
        if (line.startsWith("##")) {
          if (!attribute.equals("")) {
            tag.put(attribute, value);
          }
          attribute = line.substring(2);
          value = "";
        } else {
          value += line + "\n";
        }
      }
      if (!attribute.equals("")) {
        tag.put(attribute, value);
      }
      c.close();
    } catch (FileNotFoundException e1) {

    }
  }

  public HashMap<String, String> getTag() {
    return tag;
  }
}
